package Demo6;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 洪汤泽大帅哥
 * Date: 2024-12-22
 * Time: 11:12
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        int n = sc.nextInt();
        String string = "";

        int count = 0;
        int hang = 0;
        while (!string.equals("end")){
            string = sc.nextLine();
            if (string.indexOf(x)!=-1){
                System.out.println(hang+" "+string);
                count++;
            }
            hang++;
            if (count==n){
                break;
            }
        }
        System.out.println(count);
    }
}
